﻿using Finance.Bll;
using Finance.Dal;
using Finance.Entity;
using Finance.IBll;
using Finance.UI.Controllers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Finance.UI.Areas.FinanceManager.Controllers
{
    public class SaleDataController : AreaBaseController
    {
        //
        // GET: /FinanceManager/SaleData/
        ISaleDataBll saleDataBll = new SaleDataBll();
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Save(int userId, decimal amount, DateTime? saleDate, string remarks,int id=0)
        {
            var createUserName = this.User.Identity.Name;
            bool success = saleDataBll.Save(userId, amount, saleDate, remarks, createUserName,id);

            return Json(new { success });
        }

        public ActionResult List(string userName,DateTime? beginDate,DateTime? endDate, int? orgId=null, int pageIndex=1,int pageSize=20)
        { 
            var total=0;
            IEnumerable<ViewSaleDataEntity> data = saleDataBll.List(userName, beginDate, endDate, orgId, pageIndex, pageSize, out total);

            return Json(new { success = true, data, total });
        }

        public ActionResult Delete(int id)
        {
            bool success = saleDataBll.Delete(id);
            return Json(new { success });
        }
      
    }
}
